﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace QUAN_LY_MUON_TRA_SACH
{
    public partial class frmsuatacgia : Form
    {
        public frmsuatacgia()
        {
            InitializeComponent();
        }

        private void frmsuatacgia_Load(object sender, EventArgs e)
        {
            foreach (DataGridViewRow row in FORM_MAIN.frmmain.dataGridView2.Rows)
            {
                if (Convert.ToBoolean(row.Cells[0].Value))
                {
                    txtmatacgia.Text = row.Cells[1].Value.ToString();
                    txthoten.Text = row.Cells[2].Value.ToString();
                    cadngaysinh.Text = row.Cells[3].Value.ToString();
                    cbogioitinh.Text = row.Cells[4].Value.ToString();
                    txthocvi.Text = row.Cells[5].Value.ToString();
                }
            }

        }

        private void btnthoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnluu_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtmatacgia.Text != "")
                {
                    SqlCommand lenh = new SqlCommand("update tac_gia set ten_tgia=N'" + txthoten.Text + "'," + "ngaysinh='" + cadngaysinh.Text + "'," + "gi_tinh=N'" + cbogioitinh.Text + "'," +"hocvi=N'"+txthocvi.Text+ "' where ma_tgia='" + txtmatacgia.Text + "'", Connection.sqlConnection);
                    int n = lenh.ExecuteNonQuery();
                    MessageBox.Show("Tác giả " + txtmatacgia.Text + " đã được cập nhật!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.Close();
                }
                else
                    MessageBox.Show("Bạn chưa chọn tác giả để sửa!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Lỗi: " + ex.Message);
            }
        }
    }
}
